package com.cadre.system.service.impl;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cadre.common.exception.CadreException;
import com.cadre.common.utils.common.DateUtils;
import com.cadre.common.utils.oldutil.*;
import com.cadre.system.domain.officer.*;
import com.cadre.system.mapper.A19Mapper;
import com.cadre.system.mapper.PX_PXBXXMapper;
import com.cadre.system.service.A04Service;
import com.cadre.system.service.DIC_ZBService;
import com.cadre.system.service.PX_PXBXXService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

@Service("PX_PXBXXService")
/* loaded from: PX_PXBXXServiceImpl.class */

public class PX_PXBXXServiceImpl extends ServiceImpl<BaseMapper<PX_PXBXX>, PX_PXBXX> implements PX_PXBXXService {
    @Autowired
    private PX_PXBXXMapper PX_PXBXXMapper;
    @Resource
    private DIC_ZBService dIC_ZBService;
    @Autowired
    private A19Mapper a19Mapper;
    @Autowired
    private A04Service a04Service;

    @Override // com.tdqy.cadre.modular.profess.service.PX_PXBXXService
    public PageUtils selectList(Map<String, Object> map) {
        Page<PX_PXBXX> page = new Query(map).getPage();
        return new PageUtils(page.setRecords(this.PX_PXBXXMapper.selectList(page, map)));
    }

    @Override // com.tdqy.cadre.modular.profess.service.PX_PXBXXService
    public List<PX_PXBXX> selectListByPersonid(Map<String, Object> map) {
        return this.PX_PXBXXMapper.selectListByPersonid(map);
    }

    @Override
    public List<Tree> treeInit(String userId) {
        return this.PX_PXBXXMapper.treeInit(userId);
    }

    @Override // com.tdqy.cadre.modular.profess.service.PX_PXBXXService
    public ResultVO selectPersonListById(String ids) {
        if (StringUtils.isEmpty(ids)) {
            throw new CadreException(ResultEnum.NULL_ERROR);
        }
        List<PersonVO> list = this.PX_PXBXXMapper.selectPersonListById(Arrays.asList(StringUtils.split(ids, ",")));
        if (CollectionUtils.isEmpty(list)) {
            return ResultVOUtil.success(list);
        }
        for (PersonVO vo : list) {
            getName(vo);
            getAa01(vo);
            getAa02(vo);
            getA0191(vo);
            getA0187(vo);
        }
        return ResultVOUtil.success(list);
    }

    @Override // com.tdqy.cadre.modular.profess.service.PX_PXBXXService
    public void updateNameById(String flowid, String newName) {
        this.PX_PXBXXMapper.updateNameById(flowid, newName);
    }

    private void getName(PersonVO vo) {
        String a0105 = vo.getA0105();
        boolean b = StringUtils.isNotEmpty(a0105) && "女".equals(a0105);
        String a0130 = vo.getA0130();
        boolean b1 = StringUtils.isNotEmpty(a0130) && !"汉族".equals(a0130);
        StringBuilder sb = new StringBuilder();
        if (b && !b1) {
            sb.append("(女)");
        }
        if (b && b1) {
            sb.append("(女,");
            sb.append(a0130);
            sb.append(")");
        }
        if (!b && b1) {
            sb.append("(");
            sb.append(a0130);
            sb.append(")");
        }
        if (StringUtils.isNotBlank(sb.toString())) {
            vo.setA0101(vo.getA0101() + "\n" + sb.toString());
        }
    }

    private void getAa01(PersonVO vo) {
        Date a0106 = vo.getA0106();
        if (a0106 != null) {
            int age = AgeUtil.getCurrentAge(a0106);
            String time = new SimpleDateFormat(DateUtil.MONTG_DATE_FORMAT).format(a0106);
            vo.setAa01(time + "\n(" + age + ")");
        }
    }

    private void getAa02(PersonVO vo) {
        Map<String, String> map = new HashMap<>();
        map.put("省部级正职", "正省");
        map.put("省部级副职", "副省");
        map.put("厅局级正职", "正厅");
        map.put("厅局级副职", "副厅");
        map.put("县处级正职", "正处");
        map.put("县处级副职", "副处");
        map.put("比照正厅级", "正厅");
        map.put("比照副厅级", "副厅");
        map.put("比照正处级", "正处");
        map.put("一级巡视员", "一巡");
        map.put("二级巡视员", "二巡");
        map.put("一级调研员", "一调");
        map.put("二级调研员", "二调");
        map.put("三级调研员", "三调");
        map.put("四级调研员", "四调");
        map.put("乡科级正职", "正科");
        map.put("乡科级副职", "副科");
        map.put("科员", "科员");
        map.put("办事员", "办事员");
        map.put("一级主任科员", "一级主任科员");
        map.put("二级主任科员", "二级主任科员");
        map.put("三级主任科员", "三级主任科员");
        map.put("四级主任科员", "四级主任科员");
        StringBuilder sb = new StringBuilder();
        if (vo.getA0180() != null) {
            sb.append(DateUtils.format(vo.getA0180(), DateUtil.MONTG_DATE_FORMAT));
        }
        if (!(vo.getA0179() == null || vo.getA0179().equals("") || map.get(vo.getA0179()) == null)) {
            if (sb.length() > 0) {
                sb.append("\n");
            }
            sb.append(map.get(vo.getA0179()));
        }
        if (vo.getA0142() != null) {
            if (sb.length() > 0) {
                sb.append("\n");
            }
            sb.append(DateUtils.format(vo.getA0142(), DateUtil.MONTG_DATE_FORMAT));
        }
        if (!(vo.getA0198() == null || vo.getA0198().equals("") || map.get(vo.getA0198()) == null)) {
            if (sb.length() > 0) {
                sb.append("\n");
            }
            sb.append(map.get(vo.getA0198()));
        }
        vo.setAa02(sb.toString());
    }

    private void getA0191(PersonVO vo) {
        if (vo.getA0191() != null) {
            String a0191 = vo.getA0191();
            if (a0191.contains(" ")) {
                a0191 = a0191.substring(0, a0191.indexOf(" "));
                vo.setA0191(a0191);
            }
            if (a0191.contains("\n")) {
                a0191 = a0191.substring(0, a0191.indexOf("\n"));
                vo.setA0191(a0191);
            }
            if (a0191.contains("\r")) {
                vo.setA0191(a0191.substring(0, a0191.indexOf("\r")));
            }
        }
    }

    private void getA0187(PersonVO vo) {
        DIC_ZB dicGb6864;
        DIC_ZB dicXueli;
        A04 a04;
        if (null != vo) {
            List<A04> a04s = this.a04Service.selectList(vo.getFlowid());
            if (org.apache.commons.collections.CollectionUtils.isNotEmpty(a04s)) {
                List<A04> qrz = (List) a04s.stream().filter(a042 -> {
                    return a042.getA0449().equals("1");
                }).collect(Collectors.toList());
                List<A04> zz = (List) a04s.stream().filter(a042 -> {
                    return a042.getA0449().equals("2");
                }).collect(Collectors.toList());
                if (org.apache.commons.collections.CollectionUtils.isNotEmpty(qrz) && null != (a04 = qrz.stream().min(new Comparator<A04>() { // from class: com.tdqy.cadre.modular.profess.service.impl.PX_PXBXXServiceImpl.1
                    public int compare(A04 o1, A04 o2) {
                        String a1 = o1.getA0460();
                        String a2 = o2.getA0460();
                        if (StringUtils.isNotBlank(a1) && a1.length() < 2) {
                            a1 = a1 + 0;
                        }
                        if (StringUtils.isNotBlank(a2) && a2.length() < 2) {
                            a2 = a2 + 0;
                        }
                        if ((StringUtils.isNotBlank(a1) ? Integer.parseInt(a1) : 0) > (StringUtils.isNotBlank(a2) ? Integer.parseInt(a2) : 0)) {
                            return 1;
                        }
                        return -1;
                    }
                }).get())) {
                    DIC_ZB dicXueli2 = this.dIC_ZBService.selectByTableNameAndCode("DIC_XUELI", a04.getA0460());
                    StringBuffer sb = new StringBuffer();
                    if (null != dicXueli2) {
                        sb.append(dicXueli2.getName());
                    }
                    sb.append("\n");
                    DIC_ZB dicGb68642 = this.dIC_ZBService.selectByTableNameAndCode("DIC_GB6864", a04.getA0463());
                    if (null != dicGb68642) {
                        sb.append(dicGb68642.getName());
                    }
                    vo.setA0187(sb.toString());
                }
                if (org.apache.commons.collections.CollectionUtils.isNotEmpty(zz)) {
                    A04 a04XueLi = zz.stream().min(new Comparator<A04>() { // from class: com.tdqy.cadre.modular.profess.service.impl.PX_PXBXXServiceImpl.2
                        public int compare(A04 o1, A04 o2) {
                            String a1 = o1.getA0460();
                            String a2 = o2.getA0460();
                            if (StringUtils.isNotBlank(a1) && a1.length() < 2) {
                                a1 = a1 + 0;
                            }
                            if (StringUtils.isNotBlank(a2) && a2.length() < 2) {
                                a2 = a2 + 0;
                            }
                            if ((StringUtils.isNotBlank(a1) ? Integer.parseInt(a1) : 0) > (StringUtils.isNotBlank(a2) ? Integer.parseInt(a2) : 0)) {
                                return 1;
                            }
                            return -1;
                        }
                    }).get();
                    A04 a04XueWei = zz.stream().min(new Comparator<A04>() { // from class: com.tdqy.cadre.modular.profess.service.impl.PX_PXBXXServiceImpl.3
                        public int compare(A04 o1, A04 o2) {
                            String a1 = o1.getA0463();
                            String a2 = o2.getA0463();
                            if (StringUtils.isBlank(a1)) {
                                return -1;
                            }
                            if (StringUtils.isBlank(a2)) {
                                return 1;
                            }
                            if (a1.length() < 3) {
                                a1 = a1 + 0;
                            }
                            if (a2.length() < 3) {
                                a2 = a2 + 0;
                            }
                            if (Integer.parseInt(a1) > Integer.parseInt(a2)) {
                                return 1;
                            }
                            return -1;
                        }
                    }).get();
                    StringBuffer sb2 = new StringBuffer();
                    if (!(null == a04XueLi || null == (dicXueli = this.dIC_ZBService.selectByTableNameAndCode("DIC_XUELI", a04XueLi.getA0460())))) {
                        sb2.append(dicXueli.getName());
                    }
                    sb2.append("\n");
                    if (!(null == a04XueWei || null == (dicGb6864 = this.dIC_ZBService.selectByTableNameAndCode("DIC_GB6864", a04XueWei.getA0463())))) {
                        sb2.append(dicGb6864.getName());
                    }
                    vo.setA0190(sb2.toString());
                }
            }
        }
    }
}
